/*
 * BlackLightning.PluginLib.Modules.IModule
 * Andy Tidball
 * 
 * Project: Black Lightning Plugin Library
 * Copyright: GNU General Public License
 */

using System;
using BlackLightning.PluginLib;

namespace BlackLightning.PluginLib.Modules {
	/// <summary>
	/// Defines the interface between Black Lightning and modules it can load.
	/// </summary>
	public interface IModule : IPacketHandler {
		/// <summary>
		/// Called by Black Lightning to retrieve the value of a Property of the IModule.
		/// </summary>
		/// <param name="Property">The property to retrieve the value for.</param>
		/// <returns>The value of the requested property.</returns>
		object GetProperty(ModuleProperty Property);
	}

	/// <summary>
	/// An attribute that tags Assemblies and defines which of its classes are Black Lightning Modules.
	/// </summary>
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple=true)]
	public class BLModuleAttribute : Attribute {
		// member data
		private Type _Type; // the type that is an IModule

		/// <summary>
		/// Creates a new BLModuleAttribute.
		/// </summary>
		/// <param name="Type">A type that implements IModule and wishes to be visible to Black Lightning.</param>
		public BLModuleAttribute(Type Type) {
			_Type = Type;
		}

		/// <summary>
		/// Gets or sets the type that implements IModule and wishes to be visible to Black Lightning.
		/// </summary>
		public Type Type {
			get {
				return _Type;
			}
			set {
				_Type = value;
			}
		}
	}

	/// <summary>
	/// An attribute to be applied to IModule-derived classes to give them a name other than their type.
	/// </summary>
	[AttributeUsage(AttributeTargets.Class)]
	public class ModuleNameAttribute : Attribute {
		// member data
		private string _Name; // the name to apply to the IModule

		/// <summary>
		/// Creates a new ModuleNameAttribute.
		/// </summary>
		/// <param name="Name">The name to apply to the IModule.</param>
		public ModuleNameAttribute(string Name) {
			_Name = Name;
		}

		/// <summary>
		/// Gets or sets the name to apply to the IModule.
		/// </summary>
		public string Name {
			get {
				return _Name;
			}
			set {
				_Name = value;
			}
		}
	}

	/// <summary>
	/// An enumeration of all the properties that an IModule might have.
	/// </summary>
	public enum ModuleProperty {
		/// <summary>
		/// (string) The text that should be displayed when the user requests help about the IModule.
		/// </summary>
		HelpText,

		/// <summary>
		/// (bool?) Whether or not the module wants to receive OptionValueChangedMessages for internal Black Lightning options related to it.
		/// </summary>
		ReceiveInternalOptionUpdates
	}

	/// <summary>
	/// A helper class that implements IModule and provides helper functionality to derived classes.
	/// </summary>
	public abstract class Module : PacketHandler, IModule {
		/// <summary>
		/// Gets the value of one of the Module's properties.
		/// </summary>
		/// <param name="Property">The property to retrieve the value of.</param>
		/// <returns>The value of the requested property.</returns>
		public abstract object GetProperty(ModuleProperty Property);
	}
}
